package wordsort.test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Progressable;

import java.io.IOException;

public class TabOutputFormat extends FileOutputFormat<IntWritable, IntWritable> {

    public RecordWriter<IntWritable, IntWritable> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
        final Configuration conf = context.getConfiguration();
        final FileSystem fs = FileSystem.get(conf);
        Path outputPath = FileOutputFormat.getOutputPath(context);
        // use output path defined in WSDriver
        FSDataOutputStream out = fs.create(new Path(outputPath.toString()+"/res"));
        CustomWriter writer = new CustomWriter(out);
        return writer;
    }
}
